import {UPDATE_APP_INFO, GET_APP_INFO, IAppInfo} from './types';
import {AppInfoAction} from './action';

export const initialState: IAppInfo = {
    appId: 'cli_a03ee1eb59b9500e',
    appSecret: 'W50q9f8mhOYxx7o1clYuEdIBEiTYXc0c',
};


export function appInfoReducer(
    state: IAppInfo = initialState,
    {type, payload}: AppInfoAction
): IAppInfo {
    switch (type) {
        case UPDATE_APP_INFO: {
            initialState.appId = payload?.appId === undefined ? initialState.appId : payload.appId;
            initialState.appSecret = payload?.appSecret === undefined ? initialState.appSecret : payload.appSecret;
            return {
                appId: initialState.appId,
                appSecret: initialState.appSecret,
            };
        }
        case GET_APP_INFO: {
            return initialState;
        }
        default:
            return state;
    }
}
